﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ECCSystem.DataAccess
{
	class ClsDefect : DBObject 
    {
		public DataSet GetDefect(DateTime dtTime, int intUserID, int intFlg,int intNumber)
		{
			SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@Date", SqlDbType.DateTime),
															 new SqlParameter("@Number", SqlDbType.Int),
															 new SqlParameter("@UserID", SqlDbType.Int),
															 new SqlParameter("@Flg", SqlDbType.Int)};
			parameters[0].Value = dtTime;
			parameters[1].Value = intNumber;
			parameters[2].Value = intUserID;
			parameters[3].Value = intFlg;

			return RunProcedure("sp_Defect_GetList", parameters, "Defect");
		}

		public void AddDefect(DateTime dtTime, int intUserID, int intNumber)
        {
			SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@Time", SqlDbType.DateTime),
															 new SqlParameter("@Number", SqlDbType.Int),
															 new SqlParameter("@UserID", SqlDbType.Int),
															 new SqlParameter("@KeyID", SqlDbType.UniqueIdentifier)};

			parameters[0].Value = dtTime;
			parameters[1].Value = intNumber;
			parameters[2].Value = intUserID;
			parameters[3].Value = Guid.NewGuid();
			this.RunProcedure("sp_Defect_Add", parameters, "Defect");
        }

		public void DeleteDefect(string strID)
		{
			SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@KeyID", SqlDbType.UniqueIdentifier) };
			
			Guid guid = new Guid(strID);
			parameters[0].Value = guid;
			this.RunProcedure("sp_Defect_Delete", parameters, "Defect");
		}

		public void UpdateDefect(string strID, DateTime dtTime, int intUserID, int intNumber)
		{
			SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@Time", SqlDbType.DateTime),
															 new SqlParameter("@Number", SqlDbType.Int),
															 new SqlParameter("@UserID", SqlDbType.Int),
															 new SqlParameter("@KeyID", SqlDbType.UniqueIdentifier)};
			Guid guid = new Guid(strID);
			parameters[0].Value = dtTime;
			parameters[1].Value = intNumber;
			parameters[2].Value = intUserID;
			parameters[3].Value = guid;
			this.RunProcedure("sp_Defect_Update", parameters, "Defect");
		}
    }
}
